package compraventa.servlet;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import compraventa.modelo.*;
import compraventa.negocio.GestionMovimientos;

/**
 * Servlet implementation class MisPublicacionesServlet
 */
@WebServlet("/MisPublicacionesServlet")
public class MisPublicacionesServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MisPublicacionesServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int idusuario = 0;
		GestionMovimientos negocio = new GestionMovimientos();
		HttpSession session = request.getSession();
		Collection<ListarPublicacion> listaC;
		Collection<ListarPublicacion> listaV;
		try {
			Persona usuario_actual = (Persona)session.getAttribute("USUARIO");
			idusuario = usuario_actual.getIdPersona();
			listaC = negocio.listarcompras(idusuario);
			listaV = negocio.listarventas(idusuario);
			request.setAttribute("compra", listaC);
			request.setAttribute("venta", listaV);
			RequestDispatcher rd = request.getRequestDispatcher("scv_mispublicaciones.jsp");
			rd.forward(request, response);
		} catch (Exception e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
